function add_files()
global CONTROL DFILE NOTEFILE

testing = 0;
[allfiles] = fuf('/Volumes/firelite100gb/SESData/*.mat', 2, 'detail');

if(~isempty(CONTROL))
    s={CONTROL(:).filename}; % get list of what's in database
    s=unique(s); % just the uniques...
else
    s={};
end;

for j = 1:length(allfiles)
    fullfilename = allfiles{j};
    [p filename e] = fileparts(fullfilename);
    % if file is already in database, skip
    if(any(strmatch(filename, s)))
        fprintf(1, 'File %s already loaded; skipping\n', filename);
        continue;
    end;
    result = datac('open', fullfilename);
    if(result == 0)
        fprintf(1, 'processing %s\n', filename);
        datac('erase');
        htag = findobj('Tag', 'NoteFile');

        %   set(htag, 'value', [1:size(get(htag, 'string'), 1)]); % select them all
        ivno = 0;
        monno = 0;
        apno = 0;
        % read note file and paste information up on display
        [path, name, next, ver] = fileparts(fullfilename);
        uext=upper(next);
        if(strcmp(uext, next))
            next='.NOT';
        else
            if(~strcmp(next, '.mat') & ~strcmp(next, '.abf'))
                next = '.not';
            end;

        end;
        notefile = fullfile(path, [name, next]);
        [NOTEFILE, note_err] = note_read(notefile);
        for i = 1:length(NOTEFILE)
            rl = NOTEFILE(i).frec:NOTEFILE(i).lrec;
            if(testing)
                fprintf(1, 'Testing: would load %s  [%s]  RL: %d-%d\n', ...
                    filename, NOTEFILE(i).proto, min(rl), max(rl));
            else
                fprintf(1, 'Adding: load %s  RL: %d-%d\n', ...
                    filename, NOTEFILE(i).frec, NOTEFILE(i).lrec);
                to_control(DFILE, NOTEFILE(i)); % basic - just the selected record in the list...
                switch(DFILE.dmode)
                    case ('CC')
                        set_ccpar;

                    case ('VC')
                        set_vcpar;
                    otherwise
                end;
                %                   edit_control('update');
            end;
        end;

    else
        fprintf(1, '**** file %s could not be opened\n', filename);
    end;
end;
%edit_control('update');
return;




function [dfile] = df_convert(dfc, sfc, rl, fullfile, block)

[p f] = fileparts(fullfile);
dfile.filename = f;
dfile.fullfile = fullfile;

dfile.path = p;
dfile.ext = '.mat';
dfile.records_in_file = 1;
dfile.nr_points = dfc.Points.v;
hdr = load(fullfile, 'HFILE'); % read the header to get top information
if(isempty(hdr))
    QueMessage('read_acq_mat: File lacks Header information', 1);
    return;
end;
if(~strmatch(fieldnames(hdr), 'HFILE'))
    QueMessage(sprintf('HFILE in hdr not found in %s\n', filename));
    return;
end;
hdr = hdr.HFILE;
comment = char(hdr.Experiment.v);
dfile.comment = [];
for j = 1:size(comment,1)
    dfile.comment=strcat(dfile.comment, sprintf(' %s', comment(j,:)));
end;
dfile.Signature = hdr.Signature.v;
dfile.mode = 5; % mat file mode - not used
dfile.dmode = dfc.Data_Mode.v;

dfile.frec=rl(1);
dfile.lrec=rl(end);

dfile.nr_points = dfc.Points.v;
dfile.block = block; % save the data blocks too (only in this version)
dfile.dblock = [];
dfile.ztime = [];

dfile.record = rl;
for i = 1:length(rl)
    dfile.channels(i) = length(dfc.Channels.v);
    dfile.nr_channel(i) = dfile.channels(i);
    dfile.rate(i)=dfc.Sample_Rate.v;
    dfile.gain(i,:)=ones(1,8);
    dfile.low_pass(i,1:length(dfc.Low_Pass.v))=dfc.Low_Pass.v;
end;


dfile.ftime = 0;
dfile.junctionpot =0;
dfile.vgain = 10;
dfile.wgain = 1;
dfile.igain = 1;
dfile.slow = 0;
dfile.ztime = zeros(21, 1); % is only loaded from data itself...
dfile.refvg = 1;
dfile.refig = 1;
dfile.refwg = 1;
dfile.durs =[10 500 50];
dfile.steps = sfc.Level.v;
dfile.seq = sfc.Sequence.v;
dfile.seqpar = sfc.SeqParList.v;
dfile.seqstep = sfc.SeqStepList.v;

dfile.shkl = [];
dfile.refvgain = 1;
dfile.refigain = 1;
dfile.refwgain = 1;


return;
